package com.app.model.room 
{
	import org.puremvc.as3.patterns.proxy.Proxy;
	import org.puremvc.as3.interfaces.IProxy;
	
	import com.app.view.component.RoomMediator;
	
	import com.app.model.data.UserData;
	
	import com.peachcastle.debug.Log;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class PlayerListProxy extends Proxy implements IProxy
	{
		public static const NAME:String = 'PlayerListProxy';
		
		private var _players:Array = null;
		
		public function PlayerListProxy() 
		{
			super(NAME);
			_players = [];
		}
		
		public function getUidByPlayer(mid:int):UserData
		{
			if (_players[mid] == null) return null;
			return _players[mid];
		}
		
		public function getPlayerInSeat(seatid:int):UserData
		{
			var user:UserData = null;
			for (var i:String in _players)
			{
				if (_players[i] && _players[i] != null && (_players[i] as UserData).seatid == seatid)
				{
					user = (_players[i] as UserData);
				}
			}
			
			return user;
		}
		
		public function getSeats():Array
		{
			var data:Array = [];
			for (var i:String in _players)
			{
				if (_players[i] && _players[i] != null)
				{
					data.push((_players[i] as UserData).seatid);
				}
			}

			return data;
		}
		
		public function addPlayer(user:UserData = null):void
		{
			if (_players[user.mid]) return;
			_players[user.mid] = user;
			if (user.seatid != 0)
			{
				sendNotification(RoomMediator.ADD_PLAYER_IN_SEAT_RESPONSE, [user]);
			}
		}
		
		public function removePlayer(mid:int):void
		{
			if(_players[mid]) _players[mid] = null;
		}
		
		public function removeAll():void
		{
			_players = [];
		}
	}

}